package action;

import Impl.plateDaoImpl;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class MoveSectionAction extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("----------正在执行moveSectionAction------------");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        Integer sIdson = Integer.parseInt(request.getParameter("select1"));
        System.out.println(sIdson);

        Integer sIdfather = Integer.parseInt(request.getParameter("select2"));
        System.out.println(sIdfather);

        if(sIdson==-1)
            out.print("<script>" + "alert('未选择要移动的子板块');" + "window.history.back();" + "</script>");
        else if(sIdfather==-1)
            out.print("<script>" + "alert('未选择移动后的父板块');" + "window.history.back();" + "</script>");
        else
        {
            plateDaoImpl plateDao=new plateDaoImpl();
            if(plateDao.movePlate(sIdson,sIdfather)){
                response.sendRedirect("moveSection.jsp");
            }
            else
            {
                out.print("<script>" + "alert('移动失败');" + "window.history.back();" + "</script>");
            }
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
